<?php 
namespace app\manager\controller;

use app\admin\model\Admins;


Class Set extends Base
{
   

   public function info(){

        $data = Admins::table('wolive_service')->where('level','<>','super_manager')->paginate(8);
        foreach ($data as $v) {
            $clo_data = json_encode($v);
            $v['json'] = $clo_data;
        }

        $page = $data->render();
        $this->assign('page', $page);
        $this->assign('lister', $data);
        $this->assign('title','客服管理');
       
        return $this->fetch();
   }

   public function change(){
   	   $post =$_POST;
       
       if($post['type'] == 'close'){
       	   unset($post['type']);
       	   $res =Admins::table('wolive_business')->insert($post);
       }else{
       	   $res =Admins::table('wolive_business')->where('business_id',$post['business_id'])->delete();
       }

   	  if($res){
   	   	  return true;
   	   }else{
   	   	 return false;
   	   }
   }

   public function delete(){
   	 $post =$_POST;
   	 $res =Admins::table('wolive_service')->where('service_id',$post['id'])->find();

   	 if($res['level'] == 'manager'){
   	 	$result =Admins::table('wolive_service')->where('parent_id',$post['id'])->whereOr('service_id',$post['id'])->delete();
   	 }else{
   	 	$result =Admins::table('wolive_service')->where('service_id',$post['id'])->delete();
   	 }

     $data=['code'=>0,'msg'=>'success','data'=>$result];
       
     return $data;

   }
 
	
}
